from django.db import models
from User.models import User
# Create your models here.
class WorkClass(models.Model):
    title = models.CharField(max_length=100, verbose_name=u'标题')
    userID = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE, verbose_name=u'姓名')
    
    def __str__(self):
        return self.title

    table_name = 'work_workclass'
    class Meta:
        verbose_name_plural = "作业分组表"
        db_table = 'work_workclass'
class Work(models.Model):
    title = models.CharField(max_length=100, verbose_name=u'标题')
    msg = models.CharField(max_length=1000, verbose_name=u'备注')
    workClass = models.ForeignKey(WorkClass, on_delete=models.CASCADE)

    users = models.ManyToManyField(User, through='WorkUser')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = "作业表"
        db_table = 'work_work'

class WorkUser(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    work = models.ForeignKey(Work, on_delete=models.CASCADE)
    ROLE = (
        (u'True', u'通过'),
        (u'False', u'不通过'),
        (u'None', u'未审核'),
         (u'Skip', u'跳过')
    )
    state = models.CharField(max_length=10,choices=ROLE,default="None",verbose_name=u'审核状态')
    def __str__(self):
        return self.user.name

    class Meta:
        verbose_name_plural = "作业完成情况"
        db_table = 'work_workuser'

    # groups = models.ManyToManyField(Group, related_name='groupUsers')

class WorkIMG(models.Model):
    WorkUser = models.ForeignKey(WorkUser, on_delete=models.CASCADE)
    url = models.CharField(max_length=999, verbose_name=u'url')
    def __str__(self):
            return self.url
    class Meta:
        verbose_name_plural = "图片"
        db_table = 'work_workimg'

class WorkFile(models.Model):
    WorkUser = models.ForeignKey(WorkUser, on_delete=models.CASCADE)
    url = models.CharField(max_length=999, verbose_name=u'url')
 
    def __str__(self):
            return self.url
    class Meta:
        verbose_name_plural = "文件"
        db_table = 'work_workfile'
